//
//  AddCarProtocol.swift
//  MikerShop
//
//  Created by eme on 2016/12/9.
//  Copyright © 2016年 eme. All rights reserved.
//


import UIKit

public protocol AddCarProtocol {
    /// 添加购物的方法
    ///
    /// - Parameter saveHandle: 回调方法
    /// - Returns:
    func addCar(vc:UIViewController,model:ProductModel ,footerButonType:String ,saveHandle:@escaping ((_ product:ProductModel,_ params:[String : Any],_ clickType:String) -> Void)) -> Void
}


public extension AddCarProtocol {
    /// 添加购物的方法
    ///
    /// - Parameter saveHandle: 回调方法
    /// - Returns:
    public func addCar(vc:UIViewController,model:ProductModel ,footerButonType:String ,saveHandle:@escaping ((_ product:ProductModel,_ params:[String : Any],_ clickType:String) -> Void)) -> Void{
        let podBundle = Bundle(for: AddCar_SkuOne_Vc.self)
        guard let bundleURL = podBundle.url(forResource: "AddCarCore", withExtension: "bundle") else {
            return
        }
        guard let bundle = Bundle(url: bundleURL) else {
            return
        }
        let storyboard = UIStoryboard(name: "AddCarCore",bundle: bundle)
        /*
         //sku_type = 1 只有一个规格，取skuOne，此时商品的skus是空的,skuOne的标准属性除了skus是空的以外，其他都有值
         //sku_type=2 一维规格数组，取skus，此时商品的skuOne是空的，skus中的每个元素除了skus是空的以外，其他都有值
         //sky_type=3 二维规格数组，取skus，此时skuOne是空的，skus中的每个元素仅skuname和skus有值，每个元素的skus又是一个数组，每个元素除了skus以外都是有值
         */
        switch model.skuType {
        case 1:
            let addCarVc:AddCar_SkuOne_Vc = storyboard.instantiateViewController()
            if footerButonType == "jrphd" {
                addCarVc.footerButtons = [Footer_Button_Model(title: "加入进货单",type: "jrphd",backgroundColor: "FF8587")]
            }else if footerButonType == "ljdg"{
                addCarVc.footerButtons = [Footer_Button_Model(title: "立即订购",type: "ljdg",backgroundColor: "e31436")]
            }else{
                addCarVc.footerButtons =
                    [Footer_Button_Model(title: "加入进货单",type: "jrphd",backgroundColor: "FF8587"),
                     Footer_Button_Model(title: "立即订购",type: "ljdg",backgroundColor: "e31436")
                ]
            }
            addCarVc.view.backgroundColor = UIColor.clear
            
            addCarVc.productModel = model
            addCarVc.saveProducts = { product , params,clickType in
                saveHandle(product,params,clickType)
            }
            vc.present(addCarVc, animated: true, completion: nil)
        case 2:
            let addCarVc:AddCar_Skus_Vc = storyboard.instantiateViewController()
            if footerButonType == "jrphd" {
                addCarVc.footerButtons = [Footer_Button_Model(title: "加入进货单",type: "jrphd",backgroundColor: "FF8587")]
            }else if footerButonType == "ljdg"{
                addCarVc.footerButtons = [Footer_Button_Model(title: "立即订购",type: "ljdg",backgroundColor: "e31436")]
            }else{
                addCarVc.footerButtons =
                    [Footer_Button_Model(title: "加入进货单",type: "jrphd",backgroundColor: "FF8587"),
                     Footer_Button_Model(title: "立即订购",type: "ljdg",backgroundColor: "e31436")
                ]
            }
            addCarVc.view.backgroundColor = UIColor.clear
            addCarVc.productModel = model
            addCarVc.saveProducts = { product , params ,clickType in
                saveHandle(product,params,clickType)
            }
            vc.present(addCarVc, animated: true, completion: nil)
        case 3:
            let addCarVc:AddCar_Vc = storyboard.instantiateViewController()
            if footerButonType == "jrphd" {
                addCarVc.footerButtons = [Footer_Button_Model(title: "加入进货单",type: "jrphd",backgroundColor: "FF8587")]
            }else if footerButonType == "ljdg"{
                addCarVc.footerButtons = [Footer_Button_Model(title: "立即订购",type: "ljdg",backgroundColor: "e31436")]
            }else{
                addCarVc.footerButtons =
                    [Footer_Button_Model(title: "加入进货单",type: "jrphd",backgroundColor: "FF8587"),
                     Footer_Button_Model(title: "立即订购",type: "ljdg",backgroundColor: "e31436")
                ]
            }
            
            addCarVc.view.backgroundColor = UIColor.clear
           
            addCarVc.saveProducts = { product , params ,clickType in
                saveHandle(product,params,clickType)
            }
            vc.present(addCarVc, animated: true, completion: nil)
             addCarVc.productModel = model
        default:
            break
        }
    }
}
